import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-03-12
 * Time: 16:16
 */
public class Add implements Opera{
    public  void opera(Connection connection) throws SQLException {
        String sql = "insert into student values (?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请依次输入id与name：");
        int id = scanner.nextInt();
        String name = scanner.nextLine();
        preparedStatement.setInt(1, id);
        preparedStatement.setString(2, name);
        int rows = preparedStatement.executeUpdate();
        System.out.println(rows + " rows 被影响~");
        preparedStatement.close();
    }
}
